package com.ruoyi.web.controller.alarmmanagement;

import com.ruoyi.alarmmanagement.domain.DmWarn;
import com.ruoyi.alarmmanagement.service.IDmWarnService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 告警Controller
 *
 * @author ruoyi
 * @date 2023-09-06
 */
@RestController
@RequestMapping("/alarmmanagement/warn")
public class DmWarnController extends BaseController {
    @Autowired
    private IDmWarnService dmWarnService;

    /**
     * 查询小表告警列表
     */
//    @PreAuthorize("@ss.hasPermi('alarmmanagement:warn:list')")
    @GetMapping("/listXb")
    public TableDataInfo listXb(DmWarn dmWarn) {
        startPage();
        List<DmWarn> list = dmWarnService.selectDmWarnListXb(dmWarn);
        return getDataTable(list);
    }


    /**
     * 查询大表告警列表
     */
//    @PreAuthorize("@ss.hasPermi('alarmmanagement:warn:list')")
    @GetMapping("/listDb")
    public TableDataInfo listDb(DmWarn dmWarn) {
        startPage();
        List<DmWarn> list = dmWarnService.selectDmWarnListDb(dmWarn);
        return getDataTable(list);
    }

    /**
     * 导出小表告警列表
     */
    @PreAuthorize("@ss.hasPermi('alarmmanagement:warn:export')")
    @Log(title = "告警", businessType = BusinessType.EXPORT)
    @PostMapping("/exportXb")
    public void exportXb(HttpServletResponse response, DmWarn dmWarn) {
        List<DmWarn> list = dmWarnService.selectDmWarnListXb(dmWarn);
        ExcelUtil<DmWarn> util = new ExcelUtil<DmWarn>(DmWarn.class);
        util.exportExcel(response, list, "告警数据");
    }

    /**
     * 获取告警详细信息
     */
    @PreAuthorize("@ss.hasPermi('alarmmanagement:warn:query')")
    @GetMapping(value = "/{ID}")
    public AjaxResult getInfo(@PathVariable("ID") Long ID) {
        return success(dmWarnService.selectDmWarnByID(ID));
    }

    /**
     * 新增告警
     */
    @PreAuthorize("@ss.hasPermi('alarmmanagement:warn:add')")
    @Log(title = "告警", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DmWarn dmWarn) {
        return toAjax(dmWarnService.insertDmWarn(dmWarn));
    }

    /**
     * 修改告警
     */
    @PreAuthorize("@ss.hasPermi('alarmmanagement:warn:edit')")
    @Log(title = "告警", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DmWarn dmWarn) {
        return toAjax(dmWarnService.updateDmWarn(dmWarn));
    }

    /**
     * 删除告警
     */
    @PreAuthorize("@ss.hasPermi('alarmmanagement:warn:remove')")
    @Log(title = "告警", businessType = BusinessType.DELETE)
    @DeleteMapping("/{IDs}")
    public AjaxResult remove(@PathVariable Long[] IDs) {
        return toAjax(dmWarnService.deleteDmWarnByIDs(IDs));
    }


}
